package com.briup.ch11;

import java.io.*;

/**
 * @Author briup-adam
 * @Date 2023/10/23 下午3:32
 * @Description
 * @see java.io.DataOutputStream
 * @see  java.io.DataInputStream
 **/

public class ReadAndWriteDataType {

    public static  void  writeData(String path) throws IOException {
        FileOutputStream fos=null;
        DataOutputStream dos;

        fos=new FileOutputStream(path);
        dos=new DataOutputStream(fos);

        dos.writeByte(1);
        dos.writeDouble(23.01);
        dos.writeChar(54);
        if (dos!=null){
            dos.close();
        }
        if (fos!=null)
            fos.close();

    }
    public  static  void  readData(String path) throws IOException {
        FileInputStream fis=null;
        DataInputStream dis=null;
        fis=new FileInputStream(path);
        dis=new DataInputStream(fis);

        System.out.println(dis.readBoolean());
        System.out.println(dis.readBoolean());
        System.out.println(dis.readChar());
        System.out.println(dis.readInt());
        System.out.println(dis.readByte());
        System.out.println(dis.readByte());
        System.out.println(dis.readByte());


        if (dis!=null)
            dis.close();
        if (fis!=null)
            fis.close();


    }

    public static void main(String[] args) {
        try {
            writeData("02code/src/data.txt");
            readData("02code/src/data.txt");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
